var phoneReg = /^1[345789][0-9]{9}$/;
var pwdReg = /^.{6,16}$/;
var isPhoneRight = false;
var isPwdRight = false;

phone.onkeyup = function () {
    var phoneValue = phone.value;
    if(!phoneReg.test(phone.value)){
        phoneerror.innerHTML = "对不起，您的手机号码格式有误！";
        isPhoneRight = false;
    }else{
        phoneerror.innerHTML = "";
        isPhoneRight = true;
    }
    checkAll();
};

pwd.onkeyup = function () {
    var pwdValue = pwd.value;
    if(!pwdReg.test(pwdValue)){
      pwderror.innerHTML = "对不起，您的密码格式有误！";
      isPwdRight = false;
    }else{
        isPwdRight = true;
    }
    checkAll();
};

function checkAll() {
    if(isPhoneRight&&isPwdRight){
        loginBtn.className = "loginBtn loginBtn_active";
    }else{
        loginBtn.className = "loginBtn";
    }
}

loginBtn.onclick = function(){
    if(this.className!="loginBtn"){
        loginBtn.innerHTML = "登录中";
        $.post("http://test.hfjava.com/shop/userlogin",           $("form").serialize(),
            function(data){
                loginBtn.innerHTML = "登录";
                if(data=="false"){
                    pwderror.innerHTML = "您的用户名或密码有误，请您重试！";
                }else{
                    location.href = "../index/index.html?phone="+phone.value;
                }
            }
        );
    }
};